<template>
  <div class="container">
    <el-dialog
      :title="typeDialog.dialogType==='edit'?'修改角色':'修改供应商状态'"
      :visible.sync="typeDialog.centerDialogVisible"
      width="30%"
      center
      :lock-scroll="true"
      @closed="hideDialog"
    >
      <el-form
        ref="form"
        :rules="rules"
        :model="formData"
        label-width="120px"
        label-position="left"
      >
        <el-form-item label="供应商状态：" prop="statesType">
          <el-select v-model="formData.statesType" placeholder="请选择供应商状态">
            <el-option v-for="item in formData.statesList" :key="item" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { changeStates } from "@/api/supplier/supplierList";
export default {
  props: {
    typeDialog: Object,
    multipleSelection: Array
  },
  data() {
    return {
      formData: {
        statesList: ["正常", "停用", "冻结业务", "冻结账款"],
        statesType: ""
      },

      rules: {
        statesType: [
          { required: true, message: "选择供应商状态", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    hideDialog() {
      this.formData.statesType = "";
      this.typeDialog.centerDialogVisible = false;
    },
    //提交
    confirm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let data = {
            states: this.formData.statesType,
            id: this.multipleSelection
          };

          changeStates(data)
            .then(res => {
              if (res.code == 0) {
                this.$message({
                  message: res.msg,
                  type: "success"
                });
                this.hideDialog();
                this.$emit("upData");
              } else {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              }
            })
            .catch(err => {
              console.log(err);
            });
        }
      });
    },
    //取消
    cancel() {
      this.hideDialog();
    }
  }
};
</script>